package com.plum.netty.protocol;

import com.plum.netty.message.LoginRequestMessage;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.logging.LoggingHandler;

public class TestMessageCodec {
    public static void main(String[] args) throws Exception {
        EmbeddedChannel channel = new EmbeddedChannel(
                new LengthFieldBasedFrameDecoder(1024, 12, 4, 0, 0),
                new LoggingHandler(),
                new MessageCodec());
        // 编码
        LoginRequestMessage message = new LoginRequestMessage("mzd", "123");
        channel.writeOutbound(message);

        // 解码
        ByteBuf buf = ByteBufAllocator.DEFAULT.buffer();
        new MessageCodec().encode(null, message, buf);

        channel.writeInbound(buf);
    }
}

//        10:10:50.851 [main] DEBUG com.plum.netty.protocol.MessageCodec - 魔数 = 16909060
//        10:10:50.851 [main] DEBUG com.plum.netty.protocol.MessageCodec - 版本号 = 1
//        10:10:50.851 [main] DEBUG com.plum.netty.protocol.MessageCodec - 序列化方法 = 0
//        10:10:50.851 [main] DEBUG com.plum.netty.protocol.MessageCodec - 指令类型 = 0
//        10:10:50.851 [main] DEBUG com.plum.netty.protocol.MessageCodec - 指令类型 = 0
//        10:10:50.851 [main] DEBUG com.plum.netty.protocol.MessageCodec - 长度 = 191
//        10:10:50.851 [main] DEBUG com.plum.netty.protocol.MessageCodec - 内容 = LoginRequestMessage(super=Message(sequenceId=0, messageType=0), username=mzd, password=123)

